import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { RedisModule } from './libs/redis/redis.module';
import { PrismaModule } from './libs/prisma/prisma.module';
import { ExcelModule } from './libs/excel/excel.module';
import { EmailModule } from './libs/email/email.module';
import { JwtModule } from './libs/jwt/jwt.module';
import { UserModule } from './modules/user/user.module';
import { AuthGuard } from './common/auth.guard';
import { APP_FILTER, APP_GUARD, APP_INTERCEPTOR } from '@nestjs/core';
import { FormatResponseInterceptor } from './common/format-response.interceptor';
import { LogModule } from './libs/log/log.module';
import { InvokeRecordInterceptor } from './common/invoke-record.interceptor';
import { CustomExceptionFilter } from './common/http-exception.filter';
import { OpenaiModule } from './libs/openai/openai.module';
import { FeedbackModule } from './modules/feedback/feedback.module';
import { CardModule } from './modules/card/card.module';
import { ScheduleModule } from '@nestjs/schedule';
import { TaskModule } from './modules/task/task.module';
import { ThrottlerModule, ThrottlerGuard } from '@nestjs/throttler';
import { DataModule } from './modules/data/data.module';
import { SpiderModule } from './libs/spider/spider.module';
import { ConfigModule } from './modules/config/config.module';
import { FootballModule } from './modules/football/football.module';
import { WechatModule } from './libs/wechat/wechat.module';
import { RecommendModule } from './modules/recommend/recommend.module';

@Module({
  imports: [
    ScheduleModule.forRoot(),
    ThrottlerModule.forRoot([
      {
        ttl: 60 * 1000, // 1分钟
        limit: 300, // 正常使用
      },
      {
        name: 'short',
        ttl: 1000, // 1秒
        limit: 40, // 防止爆破
      },
      {
        name: 'long',
        ttl: 15 * 60 * 1000, // 15分钟
        limit: 2000, // 防止滥用
      },
    ]),
    PrismaModule,
    RedisModule,
    ExcelModule,
    EmailModule,
    JwtModule,
    UserModule,
    LogModule,
    OpenaiModule,
    FeedbackModule,
    CardModule,
    TaskModule,
    DataModule,
    SpiderModule,
    ConfigModule,
    FootballModule,
    WechatModule,
    RecommendModule,
  ],
  controllers: [AppController],
  providers: [
    AppService,
    {
      provide: APP_GUARD,
      useClass: ThrottlerGuard,
    },
    {
      provide: APP_GUARD,
      useClass: AuthGuard,
    },
    {
      provide: APP_INTERCEPTOR,
      useClass: FormatResponseInterceptor,
    },
    {
      provide: APP_INTERCEPTOR,
      useClass: InvokeRecordInterceptor,
    },
    {
      provide: APP_FILTER,
      useClass: CustomExceptionFilter,
    },
  ],
  exports: [AppService],
})
export class AppModule {}
